import { ObjCreate } from "../common/ObjCreate";
import { ImagesConst } from "../../resource/ImagesConst";
import { GTextFormat } from "../../../common/GTextFormat";
import { FontUtil } from "../../../common/font/FontUtil";
import { GlobalStyle } from "../../../common/global/GlobalStyle";
import { Language } from "../../../../extend/language/Language";
import { TextAlign } from "../../../../flashx/textLayout/formats/TextAlign";
import { GiftBagInfo } from "../../model/GiftBagInfo";
import { ItemData } from "../../resource/info/ItemData";
import { GiftBagConfig } from "../../resource/GiftBagConfig";
import { RandomGiftBagConfig } from "../../resource/RandomGiftBagConfig";
import { BaseItemNormal } from "../common/item/BaseItemNormal";
import { ScaleBitmap } from "../../../../com/mui/display/ScaleBitmap";
type int = number;
//class MidBody
    
    export  class MidBody /* flash.events.EventDispatcher */
    {
        constructor(arg1: Object /* flash.display.Sprite */)
        {
            
            this.box = arg1;
            this.createMid();
            return;
        }

        /* internal  */createMid(): void
        {
            var loc1=ObjCreate.createBitmap(ImagesConst.RechargeFlwBg, 188, 310, this.box);
            var loc2=ObjCreate.createBitmap(ImagesConst.RechargeFlwBg, 536, 310, this.box);
            loc2.rotationY = -180;
            var loc3=new GTextFormat(FontUtil.stXingkaiName, 18, GlobalStyle.color5Uint);
            loc3.letterSpacing = 2;
            loc3.align = flash.text.TextFormatAlign.CENTER;
            this._giftNameTF = ObjCreate.createTextField("", 255, 311, 167, 22, this.box, loc3, true);
            var loc4;
            (loc4 = new GTextFormat(FontUtil.xingkaiName, 22, GlobalStyle.color1Uint)).letterSpacing = 2;
            ObjCreate.createTextField(Language.getString(85029), 424, 308, 57, 27, this.box, loc4);
            this.midWorthBg = new Object /* flash.display.Bitmap */();
            ObjCreate.setObjAttri(this.midWorthBg, 507, 326, -1, -1, this.box);
            var loc5;
            (loc5 = new GTextFormat(FontUtil.xingkaiName, 18, GlobalStyle.color6Uint)).align = TextAlign.LEFT;
            loc5.letterSpacing = 2;
            this.oldPriceTF = ObjCreate.createTextField("199", 572, 328, 80, 27, this.box, loc5);
            loc4.color = GlobalStyle.color5Uint;
            this.curPriceTF = ObjCreate.createTextField("99", 572, 351, 80, 27, this.box, loc5);
            var loc6="<a href=\'event: 0\'><u>" + Language.getString(85030) + "</u></a>";
            var loc7;
            (loc7 = ObjCreate.createTextField(loc6, 607, 368, 57, 20, this.box, GlobalStyle.textFormat5, true)).addEventListener(flash.events.MouseEvent.CLICK, this.ruleClickHander);
            this._itemsBg = ObjCreate.createBg(224, 340, 270, 45, this.box, ImagesConst.RemainningTimeBg);
            this.midRewardItemBox = new Object /* flash.display.Sprite */();
            ObjCreate.setObjAttri(this.midRewardItemBox, 224, 346, -1, -1, this.box);
            return;
        }

        /* internal  */ruleClickHander(arg1: Object /* flash.events.Event */): void
        {
            this.dispatchEvent(new Object /* flash.events.Event */("#showRule#"));
            return;
        }

        /* internal  */getDifferentReward(arg1: Array<any>): Array<any>
        {
            var loc5=null;
            var loc6=null;
            if (arg1 == null) 
            {
                return [];
            }
            var loc1=[];
            var loc2=arg1.length;
            arg1.sortOn("code", Array.NUMERIC);
            var loc3=-1;
            var loc4=0;
            while (loc4 < loc2) 
            {
                if ((loc5 = arg1[loc4]).code != loc3) 
                {
                    (loc6 = new GiftBagInfo()).code = loc5.code;
                    loc6.num = 1;
                    loc1.push(loc6);
                    loc3 = loc5.code;
                }
                ++loc4;
            }
            return loc1;
        }

        public updataMidInfo(arg1: int, arg2: int, arg3: int, arg4: string): void
        {
            var loc4=null;
            var loc6=0;
            var loc8=0;
            var loc9=null;
            var loc10=0;
            var loc1=new ItemData(arg1);
            var loc2;
            if ((loc2 = GiftBagConfig.instance.getInfoByType(loc1.effect)) == null) 
            {
                loc2 = RandomGiftBagConfig.instance.getInfoByType(loc1.effect);
                loc2 = this.getDifferentReward(loc2);
            }
            var loc3=loc2.length;
            var loc5=this.midRewardItemBox.numChildren;
            loc6 = 0;
            var loc7=0;
            while (loc7 < loc3) 
            {
                if ((loc9 = loc2[loc7]).code) 
                {
                    if (loc6 >= loc5) 
                    {
                        (loc4 = new BaseItemNormal()).setSize(32, 32);
                        loc4.isDragAble = false;
                        loc4.isDropAble = false;
                        ObjCreate.setObjAttri(loc4, 43 * loc6, 0, -1, -1, this.midRewardItemBox);
                    }
                    else 
                    {
                        loc4 = this.midRewardItemBox.getChildAt(loc6) as BaseItemNormal;
                    }
                    loc4.itemData = new ItemData(loc9.code);
                    loc4.amount = loc9.num;
                    ++loc6;
                }
                ++loc7;
            }
            if (loc6 < loc5) 
            {
                loc10 = loc6;
                while (loc10 < loc5) 
                {
                    this.midRewardItemBox.removeChildAt(loc6);
                    ++loc10;
                }
            }
            loc8 = 350;
            this.midRewardItemBox.x = loc8 - int(loc6 * 43 * 0.5);
            this._itemsBg.width = loc6 * 43 + 100;
            this._itemsBg.x = loc8 - int(this._itemsBg.width * 0.5);
            this.oldPriceTF.text = String(arg2);
            this.curPriceTF.text = String(arg3);
            this._giftNameTF.htmlText = arg4;
            return;
        }

        /* internal */ /* var */box: Object /* flash.display.Sprite */;

        /* internal */ /* var */midRewardItemBox: Object /* flash.display.Sprite */;

        /* internal */ /* var */_giftNameTF: Object /* flash.text.TextField */;

        public /* var */midWorthBg: Object /* flash.display.Bitmap */;

        /* internal */ /* var */oldPriceTF: Object /* flash.text.TextField */;

        /* internal */ /* var */curPriceTF: Object /* flash.text.TextField */;

        /* internal */ /* var */_itemsBg: ScaleBitmap;
    }
